/*
 * HttpConnection.h
 *
 *  Created on: Jul 11, 2024
 *      Author: root
 */

#ifndef BSP_HTTP_HTTPCONNECTION_H_
#define BSP_HTTP_HTTPCONNECTION_H_

#include "HttpRequest.h"
#include "HttpResponse.h"

namespace bsp {

class HttpConnection {
public:

	HttpConnection(int sd);
	virtual ~HttpConnection();

	bool readData(std::string &read_buffer);
	bool parseReadData(std::string &read_buffer);

	bool writeDataInit();
	bool writeData(int *err);
	bool continueWriteData(int *err) {
		return writeData(err);
	}
	void writeDataClose();

	int getSd() {
		return sd;
	}

	bool keepAlive() {
		return request.isKeepAlive();
	}

	std::string getFileName() {
		return fullname;
	}

	struct iovec iov[2];
private:
	int sd;
	HttpRequest request;
	HttpResponse response;
	char buffer[COMMON_BUFFER_SIZE];
	std::string header_str;
	std::string fullname;
};

} /* namespace bsp */

#endif /* BSP_HTTP_HTTPCONNECTION_H_ */
